package com.example.interpreter2;

public class PrimitiveNode implements Node {

    private String actin;
    private String value;

    @Override
    public void interpret(Context context) {
        this.actin = context.getCurrentToken();
        context.nextToken();

        if (!this.actin.equals("PRINT")
        && !this.actin.equals("SPACE")
        && !this.actin.equals("BREAK")) {
            System.err.println("解析错误非法的语句=>\"" + this.actin + "\"");
        }

        if (this.actin.equals("PRINT")) {
            this.value = context.getCurrentToken();
            context.nextToken();
        }
    }

    @Override
    public void execute() {
        if (this.actin.equals("PRINT")) {
            System.out.print(value);
        } else if (this.actin.equals("SPACE")) {
            System.out.print(" ");
        }  else if (this.actin.equals("BREAK")) {
            System.out.println();
        } else {
            System.err.println("非法的语句=>\"" + this.actin + "\"");
        }
    }
    
}
